﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class Admin : System.Web.UI.MasterPage
{
    clsXuLy ex = new clsXuLy();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (string.IsNullOrEmpty(Convert.ToString(Session["user"])) || string.IsNullOrEmpty(Convert.ToString(Session["IDUser"])) || string.IsNullOrEmpty(Convert.ToString(Session["HoTen"])))
                Response.Redirect("Default.aspx");
            else
            {
                lbTaiKhoan.Text = Session["user"].ToString().ToUpper() + " - " + Session["HoTen"].ToString().ToUpper();
            }
            LoadMenu();
            
        }
    }
    private void LoadMenuChild(int id1, ref string kq)
    {
        DataTable dt2 = new DataTable();
        SqlParameter []p = new SqlParameter[1];
        p[0] = new SqlParameter("@IDs", id1);
        p[0].SqlDbType = SqlDbType.Int;
        dt2 = ex.GetData("sp_vnttblchucnang_ListChucNangChaByID", p);
        if (dt2.Rows.Count > 0)
        {
            kq += "<ul id='child'>";
            for (int j = 0; j < dt2.Rows.Count; j++)
            {
                kq += "<li><a href='" + dt2.Rows[j]["Link"].ToString() + "'>";
                kq += "<img src='css/cube_orange.gif' alt='gif' />&nbsp;&nbsp;" + dt2.Rows[j]["TenChucNang"].ToString() + "</a>";
                LoadMenuChild(int.Parse(dt2.Rows[j]["IDs"].ToString()), ref kq);
                kq += "</li>";
            }
            kq += "</ul>";
        }
    }
    private void LoadMenu()
    {
        string kq = "";
        kq += "<ul id='nav'>";
        DataTable dt = ex.GetData("sp_vnttblchucnang_ListChucNangCha");
        
        //SqlParameter[]p=new SqlParameter[1];
        //p[0]=new SqlParameter("@NhomND",3);
        //p[0].SqlDbType=SqlDbType.Int;
        //DataTable dt = ex.GetData("sp_LoadMenu",p);

        
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            int id1 = int.Parse(dt.Rows[i]["IDs"].ToString());
            kq += "<li class='head'><a href='" + dt.Rows[i]["Link"].ToString() + "' class='green'>";
            kq += "<img src='css/arrow.png' alt='gif' />&nbsp;&nbsp;" + dt.Rows[i]["TenChucNang"].ToString() + "</a>";

            LoadMenuChild(id1, ref kq);

            kq += "</li>";
        }
        kq += "</ul>";
        lbMenu.Text = kq;
    }

}
